<!doctype html>
<html>
<header></header>
<body>
<h2>Receipt</h2>
<?php
include('orderItem.php');
session_start();
header( "refresh:10;url=../index.html" );
$subtotal = 0;
 foreach($_SESSION['orders'] as $anOrder) //print information of each submitted order item
                    {
//                        TODO: Formatting and making each individual menu item stand out
                        echo "<h4>" . "----------"  . $anOrder->sandwichType . "----------" . "</h4>";
                        echo "Bread: " . $anOrder->bread . "</br>";
                        echo "Meat: " . $anOrder->meat . "</br>";
                        echo "Cheese: " . $anOrder->cheese . "</br>";
                        echo "Veggies: " . $anOrder->veggies . "</br>";
                        echo "Condiments: " . $anOrder->condiments . "</br>";
                        echo "Drink: " . $anOrder->drink . "</br>";
                        echo "Chips: " . $anOrder->chips . "</br>";
                        echo "Dessert: " . $anOrder->dessert . "</br>";
                        echo "Cost: $" . $anOrder->total . "</br>";
						$subtotal = $subtotal + $anOrder->total;
						
					}
$tax = sprintf("%.2f",floor(($_SESSION['orderTotal']*(.08))*100)/100); //round down to only 2 decimal places
$total = sprintf ("%.2f",($_SESSION['orderTotal'] + $tax));
$subtotal = sprintf ("%.2f", $_SESSION['orderTotal']);
    
    
     echo "</br>"; 
     echo "<h5>" . "Sub-total: $" . $subtotal . "</br>"; //displays sub-total (pre-tax)
     echo "Tax: $" . $tax . "</br>"; //displays rounded tax
     echo "Total: $" . $total . "</h5>"; //displays total with tax included 

     echo "Elliphions thanks you for your business." . "</br>";
     echo "Please enjoy your meal and have a nice day!";
	  if ( isset($_SESSION['email']) ) 
	  {
	  
                echo $_SESSION['email'] . "</br>";
				
				$subject = "RECEIPT FOR ORDER";
				
				$msg = "<h4>" . "----------"  . $anOrder->sandwichType . "----------" . "</h4>";
				$msg .= "Bread: " . $anOrder->bread . "</br>";
				$msg .= "Meat: " . $anOrder->meat . "</br>";
				$msg .= "Veggies: " . $anOrder->veggies . "</br>";
				$msg .= "Condiments: " . $anOrder->condiments . "</br>";
				$msg .= "Drink: " . $anOrder->drink . "</br>";
				$msg .= "Chips: " . $anOrder->chips . "</br>";
				$msg .= "Dessert: " . $anOrder->dessert . "</br>";
				$msg .= "Cost: $" . $anOrder->total . "</br>";
				$msg .= "TOTAL: " . $total . "<br>";
				
				$header = "Content-type:text/html;charset=iso-8859-1" . "\r\n";
                $header .= 'From: Elliphinos Sandwiches <buncandeggs@gmail.com>' . "\r\n";
				
				if ( mail(trim( $_SESSION['email']), $subject, $msg, $header) )
				{
					echo "EMAIL WAS SENT SUCESSFULLY TO " . $_SESSION['email'] . "</br>";
				}
       }
?>
</body>
</html>